<h2><strong>Quá hạn</strong></h2>
<script type="text/javascript" src="../scripts/date.js"></script>
	<script type="text/javascript">
	function ThemPhuLucHopDongXuLy()
	{
		document.getElementById("formgui").action = "index.php?do=themphuluchopdong_xuly";
		document.formgui.submit(); 
	}
	function checkRutLai(){
	 	var xmlHttp;
	 	var MaSoTietKiem = document.getElementById('MaSoTietKiem').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() > new Date(NgayLanhLai).getTime())) {
	                alert("Chưa đến ngày lãnh lãi. Ngày lãnh lãi phải >= "+NgayDenHan);
	                document.getElementById("rutlai").checked = false;
	                var TienLai = xmlHttp.responseText;
	        		//document.getElementById('LaiPhaiTra').value = TienLai;
	        		//document.getElementById('SoTienNhan').value = TienLai;
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiPhaiTra').value = TienLai;
	        		document.getElementById('SoTienNhan').value = TienLai;
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checkrutlai.php?masotietkiem='+MaSoTietKiem, true);
	    xmlHttp.send(null);
	}
	function checkRutVonTruocHan(){
	 	var xmlHttp;
	 	var MaSoTietKiem = document.getElementById('MaSoTietKiem').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() <= new Date(NgayLanhLai).getTime())) {
	                alert("Đã đến hạn rút lãi. Vui lòng chọn lại loại rút tiền");
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiPhaiTra').value = TienLai;
	        		document.getElementById('SoTienNhan').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checkrutvontruochan.php?masotietkiem='+MaSoTietKiem, true);
	    xmlHttp.send(null);
	}
	function checkRutHoanToan(){
	 	var xmlHttp;
	 	var MaSoTietKiem = document.getElementById('MaSoTietKiem').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() > new Date(NgayLanhLai).getTime())) {
	                alert("Chưa đến ngày để có thể rút hoàn toàn. Ngày rút phải >= "+NgayDenHan);
	              	document.getElementById("ruthoantoan").checked = false;
	                var TienLai = xmlHttp.responseText;
	        		//document.getElementById('LaiPhaiTra').value = TienLai;
	        		//document.getElementById('SoTienNhan').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiPhaiTra').value = TienLai;
	        		document.getElementById('SoTienNhan').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checkruthoantoan.php?masotietkiem='+MaSoTietKiem, true);
	    xmlHttp.send(null);
	}
	function tatToanSo(){
	 	var xmlHttp;
	 	var MaSoTietKiem = document.getElementById('MaSoTietKiem').value;
	    if(window.XMLHttpRequest){
	        xmlHttp = new XMLHttpRequest;
	    }
	    else if(window.ActiveXObject){
	        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    
	    xmlHttp.onreadystatechange = function(){
	        if(xmlHttp.readyState == 4){
		        var NgayLanhLai = document.getElementById('NgayLanhLai').value;
		        var NgayDenHan = document.getElementById('NgayDenHan2').value;
	        	if ((new Date(NgayDenHan).getTime() > new Date(NgayLanhLai).getTime())) {
	                alert("Chưa đến ngày để có thể tất toán sổ. Ngày tất toán phải >= "+NgayDenHan);
	              	document.getElementById("tattoanso").checked = false;
	                var TienLai = xmlHttp.responseText;
	        		//document.getElementById('LaiPhaiTra').value = TienLai;
	        		//document.getElementById('SoTienNhan').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        	else {
	        		var TienLai = xmlHttp.responseText;
	        		document.getElementById('LaiPhaiTra').value = TienLai;
	        		document.getElementById('SoTienNhan').value = Number(TienLai) + Number(document.getElementById('SoTienGui').value);
	        	}
	        }
	    }
	    xmlHttp.open('GET', '../adm/nhanvien/sotietkiem/checktattoanso.php?masotietkiem='+MaSoTietKiem, true);
	    xmlHttp.send(null);
	}
</script>
<?php
	$hopdongtindung = new hopdongtindungbs();
	$hopdongtindung->SoKheUoc = $_GET["id"];
	$danhsach = $hopdongtindung->LayDanhSach();
?>

<form id="formgui" enctype="multipart/form-data" name="formgui"  method="post" action="index.php?do=inphieuchi&id=<?php echo $_GET["id"];?>" onsubmit="return checkPostArtForm(this);">
<table style="width:950px; margin-left: 10px; table-layout: fixed;">
		<tr>
	        <td style="width:15px;padding-top:10px;">
	            <input name="loaithutien" type="radio" id="thulaiquahan" onclick="checkThuLaiQuaHan();" value="thulaiquahan"/>Thu lãi quá hạn
	        </td>
	        <td style="width:15px;padding-top:10px;">
				<input name="loaithutien" type="radio" id="thunoquahan" onclick="checkThuNoQuaHan();" value="thunoquahan"/>Thu nợ quá hạn
	        </td>
		</tr>
		<p class="requirefields">(*): Các trường bắt buộc phải có.</p>
</table>
<br/>
<table style="width:950px; margin-left: 10px; table-layout: fixed;">	
		<tr>
			<td style="width:20px;padding-top:10px;">
	        	<label for="sokheuoc">Số khế ước:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	           	<input readonly="readonly" tabindex="1" type="text" id="SoKheUoc" name="SoKheUoc" class="txt" size="54" value="<?php echo $danhsach[0]["SoKheUoc"];?>"/>   
	        </td>
	        <td style="width:15px;padding-top:10px;">

	        </td>
	        <td style="width:60px;padding-top:10px;">

	        </td>
		</tr>
		<tr>
			<?php 
				$kh = new khachhangbs();
				$kh->MaKH = $danhsach[0]["MaKH"];
				$dskhachhang = $kh->LayDanhSach();
			?>
			<td style="padding-top:10px;">
	        	<label for="tenkhachhang">Khách hàng:</label>
	        </td>	       
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="TenKhachHang" name="TenKhachHang" class="txt" size="12" value="<?php echo $dskhachhang[0]['Ho'] . " ". $dskhachhang[0]['Ten'];?>" /> 
			</td>
			<td style="padding-top:10px;">
	        	<label for="makhachhang">Mã khách hàng:</label>      	
	        </td>
			 <td style="padding-top:10px;">
	        	<input readonly="readonly" tabindex="1" type="text" id="MaKH" name="MaKH" class="txt" size="12" value="<?php echo $dskhachhang[0]['MaKH'];?>" /> 
	        </td>
		</tr>	
		<tr>
			<td style="padding-top:10px;">
	        	<label for="ngaymoso">Ngày mở sổ:</label> 
	        </td>
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="NgayMoSo" name="NgayMoSo" class="txt" size="12" value="<?php echo $danhsach[0]["NgayMoSo"];?>" />
			</td>
			<td style="padding-top:10px;">
				<label for="ngaydenhan">Ngày đến hạn:</label>
	        </td>
			<td style="padding-top:10px;">
				<input type="hidden" id="NgayDenHan2" value="<?php echo $danhsach[0]["NgayDenHan"];?>"/>
				<input readonly="readonly" tabindex="1" type="text" id="NgayDenHan" name="NgayDenHan" class="txt" size="12" value="<?php echo $danhsach[0]["NgayDenHan"];?>" />
	        </td>
		</tr>
		<tr>
			<td style="padding-top:10px;">
	        	<label for="hinhthucvay">Hình thức vay:</label>
	        </td>
			<td style="padding-top:10px;">
				<select disabled="disabled" name="MaHinhThucVay">	
            		<option value="0">-- Chọn hình thức vay --</option>	                      	
					<?php
						$hinhthucvay = new hinhthucvaybs();
						$danhsachhinhthucvay = $hinhthucvay->LayDanhSach();
						for($j = 0; $j < ($danhsachhinhthucvay != false ? count($danhsachhinhthuc) : 0); $j++)
						{
							if($danhsachhinhthucvay[$j]["MaHinhThucVay"]==$danhsach[0]["MaHinhThucVay"])		
								echo "<option selected value='{$danhsachhinhthucvay[$j]["MaHinhThucVay"]}'>{$danhsachhinhthucvay[$j]["TenHinhThucVay"]}</option>";
							else 
								echo "<option value='{$danhsachhinhthucvay[$j]["MaHinhThucVay"]}'>{$danhsachhinhthucvay[$j]["TenHinhThucVay"]}</option>";
						}
					?>
				</select>			
			</td>
			<td style="padding-top:10px;">
				<label for="laisuatquahan">Lãi suất quá hạn:</label>
	        </td>
			<td style="padding-top:10px;">
				<select disabled="disabled" name="LaiSuatVay">	
            		<option value="0">-- Chọn lãi suất vay --</option>	                      	
					<?php
						$hopdongtindung = new hopdongtindungbs();
						$danhsachhopdongtindung = $hopdongtindung->LayDanhSach();
						for($j = 1; $j < ($danhsachhopdongtindung != false ? count($danhsachhopdongtindung) : 1); $j++)
						{
							if($danhsachhopdongtindung[$j]["SoKheUoc"]==$danhsach[0]["SoKheUoc"])		
								echo "<option selected value='{$danhsachhopdongtindung[$j]["SoKheUoc"]}'>{$danhsachhopdongtindung[$j]["LaiSuatQuaHan"]}</option>";
							else 
								echo "<option value='{$danhsachhopdongtindung[$j]["SoKheUoc"]}'>{$danhsachhopdongtindung[$j]["LaiSuatQuaHan"]}</option>";
						}
					?>
				</select>			
			</td>
		</tr>	
		<tr>
			<td colspan="0">
			<hr>
			</td>
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
				<label for="sotienquahan">Số tiền quá hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="SoTienQuaHan" name="SoTienQuaHan" class="txt"/>   
	        </td>  
	        <td style="width:15px;padding-top:10px;">
	        	<label for="ngaytraquahan">Ngày trả quá hạn:</label>
	        </td>
	        <?php 
		        date_default_timezone_set('Asia/Ho_Chi_Minh');
	        ?>
			<td style="padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="NgayTraQuaHan" name="NgayTraQuaHan" class="txt" size="12" value="<?php echo date("Y-m-d", time());?>" />
			</td>    
	    </tr>  
		
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="sotientragocquahan">Số tiền trả gốc quá hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input tabindex="1" type="text" id="SoTienTraGocQuaHan" name="SoTienTraGocQuaHan" class="txt" " />
	        </td>
	        <td style="width:15px;padding-top:10px;">
				<label for="sotientralaiquahan">Số tiền trả lãi quá hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
				<input readonly="readonly" tabindex="1" type="text" id="SoTienTraLaiQuaHan" name="SoTienTraLaiQuaHan" class="txt" />
	        </td>    
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="dunoquahan">Dư nợ quá hạn:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input readonly="readonly" tabindex="1" type="text" id="DuNoQuaHan" name="DuNoQuaHan" class="txt" />   
	        </td>
		</tr>
		<tr>
			<td colspan="0">
			<hr>
			</td>
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="sobuttoan">Số bút toán:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	            <input readonly="readonly" tabindex="1" type="text" name="SoButToan" class="txt" size="54" value="<?php include 'getsobuttoan.php';?>"/>   
	        </td>
	        <td style="width:15px;padding-top:10px;">

	        </td>
	        <td style="width:60px;padding-top:10px;">

	        </td>
		</tr>
		<tr>
			<td style="width:15px;padding-top:10px;">
	        	<label for="nhanvienlapso">Nhân viên thực hiện:</label>
	        </td>
	        <td style="width:60px;padding-top:10px;">
	        	<?php 
	        		$nguoidung = new nguoidungbs();
	        		$nguoidung->MaNguoiDung = $_SESSION["MaND"];
	        		$danhsach = $nguoidung->LayDanhSach();
	        		$HoTen = $danhsach[0]["Ho"]." ".$danhsach[0]["Ten"];
	        	?>
	        	<input type="hidden" name="MaNhanVien" value="<?php echo $danhsach[0]['MaNguoiDung'] ?>"/>
	            <input readonly="readonly" tabindex="1" type="text" name="TenNhanVien" class="txt" size="54" value="<?php echo $HoTen; ?>"/>   
	        </td>
	        <td style="width:15px;padding-top:10px;">

	        </td>
	        <td style="width:60px;padding-top:10px;">

	        </td>
		</tr>		
</table>

<br/>
<br/>
<p align="center">
	<input type="submit" class="button small blue" value="In phiếu thu tiền"/>
	&nbsp &nbsp &nbsp
	<a href="javascript:PhuLucHopDongXuLy();" class="button small blue">Hoàn tất</a>	
</p>
</form>

<?php
	if(isset($_SESSION["LoiPhuLucHopDong"]))
	{
		echo $_SESSION["LoiPhuLucHopDong"];
		unset($_SESSION["LoiPhuLucHopDong"]);
	}
?>

<script type="text/javascript">
function checkPostArtForm(frm)
{
	return true;
}
</script>

